<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width=" ">
      <el-form-item label="商品名称" prop="goodsName">
        <el-input v-model="queryParams.goodsName" placeholder="请输入商品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--      <el-form-item label="商品介绍" prop="goodsIntro">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.goodsIntro"-->
      <!--          placeholder="请输入商品介绍"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="商品原价" prop="goodsPrice">
        <el-input v-model="queryParams.goodsPrice" placeholder="请输入商品原价" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--      <el-form-item label="商品折扣系数" prop="goodsDiscount">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.goodsDiscount"-->
      <!--          placeholder="请输入商品折扣系数"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!-- <el-form-item label="折合积分数" prop="usePoints">
        <el-input v-model="queryParams.usePoints" placeholder="请输入折合积分数" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="商店id" prop="shopId">
        <el-input v-model="queryParams.shopId" placeholder="请输入商店id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--      <el-form-item label="销售方式" prop="saleMode">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.saleMode"-->
      <!--          placeholder="请输入销售方式"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="关联商品id" prop="relateGoodsId">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.relateGoodsId"-->
      <!--          placeholder="请输入关联商品id"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="商品类型id" prop="goodsTypeId">
        <el-input v-model="queryParams.goodsTypeId" placeholder="请输入商品类型id" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="规格" prop="stander">
        <el-input v-model="queryParams.stander" placeholder="请输入规格" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="库存" prop="inventory">
        <el-input v-model="queryParams.inventory" placeholder="请输入库存" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="是否包邮" prop="feeShipping">
        <template slot="label">
          <span>
            是否包邮
            <el-tooltip class="item" effect="dark" content="0-不包邮，1-包邮" placement="top">
              <i class="el-icon-question"></i>
            </el-tooltip>
          </span>
        </template>
        <el-input v-model="queryParams.feeShipping" placeholder="请输入(0-不包邮，1-包邮)" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--      <el-form-item label="评价Id" prop="evaluateId">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.evaluateId"-->
      <!--          placeholder="请输入评价Id"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="删除标识"  prop="isDel">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.isDel"-->
      <!--          placeholder="请输入删除标识（0正常，1停用）"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="推荐标识" prop="recommend">
        <template slot="label">
          <span>
            推荐标识
            <el-tooltip class="item" effect="dark" content="0-不推荐，1-推荐" placement="top">
              <i class="el-icon-question"></i>
            </el-tooltip>
          </span>
        </template>
        <el-input v-model="queryParams.recommend" placeholder="请输入推荐标识(0-不推荐，1-推荐)" clearable
          @keyup.enter.native="handleQuery" style="width: 240px !important;" />
      </el-form-item>
      <el-form-item label="删除标识" prop="isDel">
        <template slot="label">
          <span>
            删除标识
            <el-tooltip class="item" effect="dark" content="0-正常，1-停用" placement="top">
              <i class="el-icon-question"></i>
            </el-tooltip>
          </span>
        </template>
        <el-input v-model="queryParams.isDel" clearable placeholder="请输入删除标识" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--      <el-form-item label="扩展字段2" prop="ext2">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ext2"-->
      <!--          placeholder="请输入扩展字段2"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="扩展字段3" prop="ext3">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ext3"-->
      <!--          placeholder="请输入扩展字段3"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="扩展字段4" prop="ext4">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ext4"-->
      <!--          placeholder="请输入扩展字段4"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="扩展字段5" prop="ext5">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.ext5"-->
      <!--          placeholder="请输入扩展字段5"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
    </el-form>

    <el-row :gutter="10" class="mb8" style="display: flex;">
      <el-col style="justify-content: left;" :span="20">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:goods:add']">新增</el-button>
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['system:goods:edit']">修改</el-button>
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:goods:remove']">删除</el-button>
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:goods:export']">导出</el-button>
      </el-col>
      <el-col style="justify-content: right;" class="text-right" v-show="showSearch" :span="2.5">
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :span="1.5"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="goodsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="商品id" align="center" prop="goodsId" />
      <el-table-column label="商品名称" align="center" width="150" prop="goodsName" />
      <!-- <el-table-column label="商品介绍" align="center" width="150" prop="goodsIntro" /> -->
      <el-table-column label="商品图片" align="center" prop="goodsImage">
        <template slot-scope="scope">
          <p v-if="scope.row.goodsImage == null">无图片</p>
          <image-preview v-if="scope.row.goodsImage != null" :src="scope.row.goodsImage" :width="50" :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="商品原价" align="center" prop="goodsPrice" />
      <!-- <el-table-column label="商品折扣系数" align="center" prop="goodsDiscount" /> -->
      <!-- <el-table-column label="折合积分数" align="center" prop="usePoints" /> -->
      <!-- <el-table-column label="商店id" align="center" prop="shopId" /> -->
      <el-table-column label="商店名称" align="center" prop="shopName" />
      <el-table-column label="销售方式" align="center" prop="saleMode" />
      <!-- <el-table-column label="关联商品id" align="center" prop="relateGoodsId" width="100" /> -->
      <!-- <el-table-column label="商品类型id" align="center" prop="goodsTypeId" width="100" /> -->
      <el-table-column label="商品类型名称" align="center" prop="goodsTypeValue" />
      <!-- <el-table-column label="规格" align="center" prop="stander" /> -->
      <el-table-column label="库存" align="center" prop="inventory" />
      <el-table-column label="是否包邮" align="center" prop="feeShipping" />
      <!-- <el-table-column label="关联商品名称" align="center" prop="relateGoodsName" /> -->
      <!-- <el-table-column label="评价Id" align="center" prop="evaluateId" /> -->
      <el-table-column label="推荐标识" align="center" prop="recommend" />
      <el-table-column label="删除标识" align="center" prop="isDel" />
      <!-- <el-table-column label="销售开始时间" align="center" prop="saleStartDate" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.saleStartDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="销售结束时间" align="center" prop="saleEndDate" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.saleEndDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column> -->
      <!--      <el-table-column label="扩展字段2" align="center" prop="ext2" />-->
      <!--      <el-table-column label="扩展字段3" align="center" prop="ext3" />-->
      <!--      <el-table-column label="扩展字段4" align="center" prop="ext4" />-->
      <!--      <el-table-column label="扩展字段5" align="center" prop="ext5" />-->
      <!-- <el-table-column label="创建时间" align="center" prop="createTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="更新时间" align="center" prop="updateTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime) }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)"
            v-hasPermi="['monitor:job:query']">详细</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改商品管理对话框 -->
    <el-dialog :title="title" :visible.sync="openEdit" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="商品id" prop="goodsId">
          <el-input v-model="form.goodsId" placeholder="不必填写，自动生成" readonly />
        </el-form-item>
        <el-form-item label="商品名称" prop="goodsName">
          <el-input v-model="form.goodsName" placeholder="请输入商品名称" />
        </el-form-item>
        <el-form-item label="商品宣传图片" prop="goodsImage">
          <image-goodsImg-upload v-model="form.goodsImage" />
        </el-form-item>
        <el-form-item label="商品介绍" prop="goodsIntro">
          <editor v-model="form.goodsIntro" :min-height="192" placeholder="请输入商品介绍" />
        </el-form-item>
        <el-form-item label="商品原价" prop="goodsPrice">
          <el-input v-model="form.goodsPrice" placeholder="请输入商品原价" />
        </el-form-item>
        <el-form-item label="商品折扣系数" prop="goodsDiscount">
          <el-input v-model="form.goodsDiscount" placeholder="请输入商品折扣系数" />
        </el-form-item>
        <el-form-item label="折合积分数" prop="usePoints">
          <el-input v-model="form.usePoints" placeholder="请输入折合积分数" />
        </el-form-item>
        <el-form-item label="商店id" prop="shopId">
          <el-input v-model="form.shopId" placeholder="请输入商店id" />
        </el-form-item>
        <el-form-item label="销售方式" prop="saleMode">
          <el-input v-model="form.saleMode" placeholder="请输入销售方式" />
        </el-form-item>
        <el-form-item label="关联商品id" prop="relateGoodsId">
          <el-input v-model="form.relateGoodsId" placeholder="请输入关联商品id" />
        </el-form-item>
        <el-form-item label="商品类型id" prop="goodsTypeId">
          <el-input v-model="form.goodsTypeId" placeholder="请输入商品类型id" />
        </el-form-item>
        <el-form-item label="规格" prop="stander">
          <el-input v-model="form.stander" placeholder="请输入规格" />
        </el-form-item>
        <el-form-item label="库存" prop="inventory">
          <el-input v-model="form.inventory" placeholder="请输入库存" />
        </el-form-item>
        <el-form-item label="是否包邮"  prop="feeShipping">
          <template slot="label">
            <span>
              是否包邮
              <el-tooltip class="item" effect="dark" content="0-不包邮，1-包邮" placement="top">
                <i class="el-icon-question"></i>
              </el-tooltip>
            </span>
          </template>
          <el-input v-model="form.feeShipping" placeholder="请输入(0-不包邮，1-包邮)" />
        </el-form-item>
        <!-- <el-form-item label="评价id" prop="evaluateId">
          <el-input v-model="form.evaluateId" placeholder="请输入评价id" />
        </el-form-item> -->
        <el-form-item label="推荐标识" prop="recommend">
          <template slot="label">
            <span>
              推荐标识
              <el-tooltip class="item" effect="dark" content="0-不推荐，1-推荐" placement="top">
                <i class="el-icon-question"></i>
              </el-tooltip>
            </span>
          </template>
          <el-input v-model="form.recommend" placeholder="请输入推荐标识（0-不推荐，1-推荐）" />
        </el-form-item>
        <el-form-item label="销售开始时间" prop="saleStartDate">
          <el-date-picker clearable v-model="form.saleStartDate" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择销售开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="销售结束时间" prop="saleEndDate">
          <el-date-picker clearable v-model="form.saleEndDate" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择销售结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="删除标识" prop="isDel"><template slot="label">
          <span>
            删除标识
            <el-tooltip class="item" effect="dark" content="0-正常，1-停用" placement="top">
              <i class="el-icon-question"></i>
            </el-tooltip>
          </span>
        </template>
          <el-input v-model="form.isDel" placeholder="请输入删除标识（0正常，1停用）" />
        </el-form-item>
        <!--        <el-form-item label="扩展字段2" prop="ext2">-->
        <!--          <el-input v-model="form.ext2" placeholder="请输入扩展字段2" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段3" prop="ext3">-->
        <!--          <el-input v-model="form.ext3" placeholder="请输入扩展字段3" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段4" prop="ext4">-->
        <!--          <el-input v-model="form.ext4" placeholder="请输入扩展字段4" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段5" prop="ext5">-->
        <!--          <el-input v-model="form.ext5" placeholder="请输入扩展字段5" />-->
        <!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="title" :visible.sync="openView" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="商品id" prop="goodsId">
          <el-input v-model="form.goodsId" placeholder="不必填写，自动生成" readonly />
        </el-form-item>
        <el-form-item label="商品名称" prop="goodsName">
          <el-input v-model="form.goodsName" placeholder="未填入商品名称" readonly/>
        </el-form-item>
        <el-form-item label="商品宣传图片" prop="goodsImage">
          <template slot-scope="scope">
            <p v-if="form.goodsImage == null">无图片</p>
            <image-preview v-if="form.goodsImage != null" :src="form.goodsImage" :width="50" :height="50" />
          </template>
        </el-form-item>
        <el-form-item label="商品介绍" prop="goodsIntro">
          <editor v-model="form.goodsIntro" :min-height="192" placeholder="未填入商品介绍" readonly />
        </el-form-item>
        <el-form-item label="商品原价" prop="goodsPrice">
          <el-input v-model="form.goodsPrice" placeholder="未填入商品原价" readonly/>
        </el-form-item>
        <el-form-item label="商品折扣系数" prop="goodsDiscount">
          <el-input v-model="form.goodsDiscount" placeholder="未填入商品折扣系数" readonly/>
        </el-form-item>
        <el-form-item label="折合积分数" prop="usePoints">
          <el-input v-model="form.usePoints" placeholder="未填入折合积分数" readonly/>
        </el-form-item>
        <el-form-item label="商店id" prop="shopId">
          <el-input v-model="form.shopId" placeholder="未填入商店id" readonly/>
        </el-form-item>
        <el-form-item label="商店名称" prop="shopId">
          <template slot="label">
            <span>
              商店名称
              <el-tooltip class="item" effect="dark" content="点击将前往“商店管理”修改" placement="top">
                <i class="el-icon-question"></i>
              </el-tooltip>
            </span>
          </template>
          <el-input v-model="form.shopName" placeholder="不必填写，自动生成" @click.native="handleClickShop" readonly/>
        </el-form-item>
        <el-form-item label="销售方式" prop="saleMode">
          <el-input v-model="form.saleMode" placeholder="未填入销售方式" readonly/>
        </el-form-item>
        <el-form-item label="关联商品id" prop="relateGoodsId">
          <el-input v-model="form.relateGoodsId" placeholder="未填入关联商品id" readonly/>
        </el-form-item>
        <el-form-item label="商品类型id" prop="goodsTypeId">
          <el-input v-model="form.goodsTypeId" placeholder="未填入商品类型id" readonly/>
        </el-form-item>
        <el-form-item label="商品类型值" prop="goodsTypeValue">
          <el-input v-model="form.goodsTypeValue" placeholder="不必填写，自动生成" readonly/>
        </el-form-item>
        <el-form-item label="规格" prop="stander">
          <el-input v-model="form.stander" placeholder="未填入规格" readonly/>
        </el-form-item>
        <el-form-item label="库存" prop="inventory">
          <el-input v-model="form.inventory" placeholder="未填入库存" readonly/>
        </el-form-item>
        <el-form-item label="是否包邮"  prop="feeShipping">
          <template slot="label">
            <span>
              是否包邮
              <el-tooltip class="item" effect="dark" content="0-不包邮，1-包邮" placement="top">
                <i class="el-icon-question"></i>
              </el-tooltip>
            </span>
          </template>
          <el-input v-model="form.feeShipping" placeholder="未填入(0-不包邮，1-包邮)" readonly/>
        </el-form-item>
        <!-- <el-form-item label="评价id" prop="evaluateId">
          <el-input v-model="form.evaluateId" placeholder="未填入评价id" />
        </el-form-item> -->
        <el-form-item label="推荐标识" prop="recommend">
          <template slot="label">
            <span>
              推荐标识
              <el-tooltip class="item" effect="dark" content="0-不推荐，1-推荐" placement="top">
                <i class="el-icon-question"></i>
              </el-tooltip>
            </span>
          </template>
          <el-input v-model="form.recommend" placeholder="未填入推荐标识（0-不推荐，1-推荐）" readonly />
        </el-form-item>
        <el-form-item label="销售开始时间" prop="saleStartDate">
          <el-date-picker clearable v-model="form.saleStartDate" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="未填入销售开始时间" readonly>
          </el-date-picker>
        </el-form-item>
        <el-form-item label="销售结束时间" prop="saleEndDate">
          <el-date-picker clearable v-model="form.saleEndDate" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="未填入销售结束时间" readonly>
          </el-date-picker>
        </el-form-item>
        <el-form-item label="删除标识" prop="isDel">
          <template slot="label">
            <span>
              删除标识
              <el-tooltip class="item" effect="dark" content="0-正常，1-停用" placement="top">
                <i class="el-icon-question"></i>
              </el-tooltip>
            </span>
          </template>
          <el-input v-model="form.isDel" placeholder="未填入删除标识（0-正常，1-停用）" readonly/>
        </el-form-item>
        <!--        <el-form-item label="扩展字段2" prop="ext2">-->
        <!--          <el-input v-model="form.ext2" placeholder="请输入扩展字段2" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段3" prop="ext3">-->
        <!--          <el-input v-model="form.ext3" placeholder="请输入扩展字段3" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段4" prop="ext4">-->
        <!--          <el-input v-model="form.ext4" placeholder="请输入扩展字段4" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="扩展字段5" prop="ext5">-->
        <!--          <el-input v-model="form.ext5" placeholder="请输入扩展字段5" />-->
        <!--        </el-form-item>-->
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { listGoods, getGoods, delGoods, addGoods, updateGoods } from "@/api/system/goods";
// 引入商店信息查询
import { getShop } from "@/api/system/shop";
import { getDicts } from "@/api/system/dict/data";

export default {
  name: "Goods",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商品管理表格数据
      goodsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      openEdit: false,
      // 是否显示详细弹出层
      openView: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        goodsName: null,
        goodsIntro: null,
        goodsImage: null,
        goodsPrice: null,
        goodsDiscount: null,
        usePoints: null,
        shopId: null,
        saleMode: null,
        relateGoodsId: null,
        goodsTypeId: null,
        stander: null,
        inventory: null,
        ext1: null,
        isDel: null,
        recommend: null,
        saleStartDate: null,
        saleEndDate: null,
        feeShipping: null,
        ext2: null,
        ext3: null,
        ext4: null,
        ext5: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商品管理列表 */
    async getList() {
      this.loading = true;
      try {
        const response = await listGoods(this.queryParams);
        this.goodsList = response.rows;
        this.total = response.total;
        for (let i = 0; i < this.goodsList.length; i++) {
          this.$set(this.goodsList[i], 'goodsTypeValue', await this.getGoodsType(this.goodsList[i].goodsTypeId));
          // console.log('this.goodsList[i].goodsTypeValue:', this.goodsList[i].goodsTypeValue);
        }
        await this.updateShopName();
        await this.updateRelateGoodsName();
      } catch (error) {
        console.error('获取地址列表失败:', error);
      } finally {
        this.loading = false;
      }
    },
    // 新增元素的商店名称
    async updateShopName() {
      for (let i = 0; i < this.goodsList.length; i++) {
        // console.log(this.goodsList[i].shopId);
        let shopInfo = await getShop(this.goodsList[i].shopId);
        this.$set(this.goodsList[i], 'shopName', shopInfo.data.shopName);
      }
    },
    // 根据字典，获取商品的类型名称
    async getGoodsType(key) {
      key = key.toString();
      // console.log('key:',key);
      let goodsTypeNew = '';
      const goodsDict = await getDicts("goods_type");
      // console.log(goodsDict.data);
      goodsDict.data.forEach(item => {
        if (item.dictValue === key) {
          goodsTypeNew = item.dictLabel;
        }
      });
      // console.log(goodsTypeNew);
      return goodsTypeNew;
    },
    handleClickShop() {
      // 这里可以弹出确认框，或者直接跳转
      this.$confirm('确定将前往“商店管理”修改?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        // 用户点击确认后的逻辑，例如跳转
        this.goToShop();
      }).catch(() => {
        // 用户点击取消后的逻辑（如果有需要）
      });
    },
    // 前往商店管理页面
    goToShop() {
      console.log("跳转到商店管理页面");
      this.$router.push({ path: '/tanpuhui/shop' });
      this.openEdit = false;
    },
    // 取消按钮
    cancel() {
      this.openEdit = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        goodsId: null,
        goodsName: null,
        goodsIntro: null,
        goodsImage: null,
        goodsPrice: null,
        goodsDiscount: null,
        usePoints: null,
        shopId: null,
        saleMode: null,
        relateGoodsId: null,
        goodsTypeId: null,
        stander: null,
        inventory: null,
        ext1: null,
        isDel: null,
        createTime: null,
        updateTime: null,
        recommend: null,
        saleStartDate: null,
        saleEndDate: null,
        feeShipping: null,
        ext2: null,
        ext3: null,
        ext4: null,
        ext5: null
      };
      this.resetForm("form");
    },
    /** 详细按钮操作 */
    handleView(row) {
      this.openView = true;
      this.form = row;
      this.title = "商品详细（如需修改，请通过修改按钮进行修改）";
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.goodsId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.openEdit = true;
      this.title = "添加商品管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const goodsId = row.goodsId || this.ids
      getGoods(goodsId).then(response => {
        this.form = response.data;
        this.openEdit = true;
        this.title = "修改商品管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.goodsId != null) {
            updateGoods(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openEdit = false;
              this.getList();
            });
          } else {
            addGoods(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.openEdit = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const goodsIds = row.goodsId || this.ids;
      this.$modal.confirm('是否确认删除商品管理Id为"' + goodsIds + '"的数据项？').then(function () {
        return delGoods(goodsIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/goods/export', {
        ...this.queryParams
      }, `goods_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
